package cn.zxyh;

import cn.zxyh.filter.CorsFilter;
import cn.zxyh.filter.LoginVerifyFilter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@MapperScan("cn.zxyh.mapper")
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }

    @Bean
    public FilterRegistrationBean corsFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new CorsFilter());
        registration.addUrlPatterns("/*");
        registration.setName("corsFilter");
        //将其注册在其他过滤器的前面
        registration.setOrder(0);
        return registration;
    }

    @Bean
    public FilterRegistrationBean loginVarifyFilterRegistration(LoginVerifyFilter filter) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(filter);
        registration.addUrlPatterns("/*");
        registration.addInitParameter("exclusions", "/login"); // 登录页面不拦截,这里排除无效，不知道什么原因！！！
        registration.setName("loginVarifyFilter");
        //将其注册在其他过滤器的前面
        registration.setOrder(1);
        return registration;
    }
}
